/*
	Flie:						CreditsState.cpp
	Course:				SGP 1208
	Author:				Kori Po
	Purpose:			Display the ending credits
*/

#include "CreditsState.h"
#include "MainMenuState.h"
#include "Game.h"
#include "TempFont.h"

CCreditsState::CCreditsState(void)
{
	m_3DGuy					= nullptr;
	m_InputGuy			= nullptr;
	m_TextureGuy		= nullptr;
	m_AudioGuy			= nullptr;

	m_MenuFont			= nullptr;

	m_nBackGroundID = -1;

	m_Finished = false;

	m_szCreditLine[0] = "DESIGN DEV: RICHARD(KORI) PO";
	m_szCreditLine[1] = "DESIGN DEV: WILL POLOSKI";
	m_szCreditLine[2] = "AI DEV: NATT WHITE";
	m_szCreditLine[3] = "MISC DEV:MATT BERRY";
	m_szCreditLine[4] = "PRODUCER: ROB MARTINEZ ";
	m_szCreditLine[5] = "ARTIST: CHRIS JOHOSKI";
	m_szCreditLine[6] = "COFFEE";
	m_szCreditLine[7] = "SUGER";
	m_szCreditLine[8] = "INSTRUCTOR: JOHN OLESKI";
	m_szCreditLine[9] = "SCHOOL: FULL SAIL UNIVERSITY";
}


CCreditsState::~CCreditsState(void)
{

}

CCreditsState* CCreditsState::GetInstance( void )
{
	static CCreditsState s_instance;
	return &s_instance;
}

// EnE Functions
void CCreditsState::Enter(void)	
{
	m_3DGuy					= CSGD_Direct3D::GetInstance();
	m_InputGuy			= CSGD_DirectInput::GetInstance();
	m_TextureGuy		= CSGD_TextureManager::GetInstance();
	m_AudioGuy			= CSGD_XAudio2::GetInstance();

	m_nBackGroundID	= m_TextureGuy->LoadTexture(_T("Resource/TempFusionBackground.png"), D3DCOLOR_XRGB(255,255,255));

	m_MenuFont = new CTempFont( );

}

void CCreditsState::Exit(void)
{
	delete m_MenuFont;
	m_MenuFont = nullptr;

	m_3DGuy					= nullptr;
	m_InputGuy			= nullptr;
	m_TextureGuy		= nullptr;
	m_AudioGuy			= nullptr;
}
	
// Running Functions
bool CCreditsState::Input(void)
{
	if( m_InputGuy->KeyPressed( DIK_ESCAPE )  ||  m_InputGuy->JoystickButtonPressed( 2, 0) )
	{
		CGame* TheGame	=	CGame::GetInstance();
		CMainMenuState* TheMenu = CMainMenuState::GetInstance();
		TheGame->ChangeState(TheMenu);
		return true;
	}

	if( m_InputGuy->KeyDown( DIK_LMENU ) && m_InputGuy->KeyPressed( DIK_RETURN )|| m_InputGuy->KeyDown( DIK_RMENU ) && m_InputGuy->KeyPressed( DIK_RETURN ) )
	{
			CGame* TheGame	=	CGame::GetInstance();
			TheGame->SetIsWindowed(!TheGame->GetIsWindowed());
			m_3DGuy->ChangeDisplayParam(TheGame->GetScreenWidth(),TheGame->GetScreenHeight(),TheGame->GetIsWindowed());
			return true;
	}

	return true;
}


void CCreditsState::Update(float fElapsedTime)
{
	m_nScroller += 100 * fElapsedTime;

	if(m_Finished)
	{
		m_Finished = !m_Finished;
		m_nScroller = 0;
		CGame* TheGame	=	CGame::GetInstance();
		CMainMenuState* TheMenu = CMainMenuState::GetInstance();
		TheGame->ChangeState(TheMenu);
	}
}

void CCreditsState::Render(void)
{
	CGame* TheGame = CGame::GetInstance();
	//Draw Background
	RECT ToDraw = {0,0,1920,1080};
	m_TextureGuy->Draw(m_nBackGroundID,0,0,1,1,&ToDraw);

	for(int x = 0; x < CREDITLINES; x++)
	{
			m_MenuFont->Print(m_szCreditLine[x], 100,(TheGame->GetScreenHeight()/4) + (75 * x) - m_nScroller, 1, D3DCOLOR_XRGB(255,0,255));
			if((TheGame->GetScreenHeight()/4) + (75 * (CREDITLINES - 1)) - m_nScroller - 10 <= 0)
			{
				m_Finished = true;
			}
	}

	m_MenuFont->Print("CREDITS", TheGame->GetScreenWidth()/2 - 60, 20, 1, D3DCOLOR_XRGB(255,0,255));
}